<template>
 <div class>
   <!--查询及新增 start-->
    <el-card>
      <el-form
      size="mini"
        :model="ruleForm"
        :inline="true"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <my-form-item label="评分方案名称" prop="nameLike">
          <el-input v-model="ruleForm.nameLike"></el-input>
        </my-form-item>
        <my-form-item label="是否生效" prop="isEnable">
          <el-select v-model="ruleForm.isEffect" placeholder="==请选择==">
            <el-option label="是" value="1"></el-option>
            <el-option label="否" value="0"></el-option>
          </el-select>
        </my-form-item>
        <my-form-item>
          <el-button type="primary" @click="submitForm()">查询</el-button>
          <el-button @click="resetForm()">重置</el-button>
          <el-button icon="el-icon-plus" type="success" round @click="addScheme">新增</el-button>
        </my-form-item>
      </el-form>
    </el-card>
    <!--查询及新增 end-->

    <!--表单 start-->
    <el-table :data="tableData" border stripe style="width: 100%">
      <el-table-column prop="name" label="评分方案名称" width="200" align="center"></el-table-column>
      <el-table-column prop="code" label="评分方案编码" width="140" align="center"></el-table-column>
      <el-table-column prop="retionRate" label="定量比例(%)" width="120" align="center"></el-table-column>
      <el-table-column prop="determineNatureRate" label="定性比例(%)" width="120" align="center"></el-table-column>
      <el-table-column prop="isEffect" label="是否启用" width="80" align="center" :formatter="formatData"></el-table-column>
      <el-table-column prop="effectDate" label="启用日期" width="110" align="center" :formatter="dateFormatter"></el-table-column>     
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini" @click="levelSetting(scope.$index, scope.row)">评级设置</el-button>
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
          <el-button size="mini" @click="preview(scope.$index, scope.row)">浏览</el-button>
          <el-button size="mini" @click="handleDistribution(scope.$index, scope.row)">分配行业</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--表单 end-->

    <!--分页 start-->
    <el-card style="text-align:right;">
        <el-pagination @size-change="handleSizeChange" 
                    @current-change="handleCurrentChange" 
                    :current-page="currentPage" 
                    :page-sizes="[10, 20, 30, 40]" 
                    :page-size="100" background 
                    layout="total, sizes, prev, pager, next" 
                    :total="totalSize"></el-pagination>
    </el-card>
    <!--分页 end-->
 </div>
</template>
<script>
export default {
    data(){
        return {
          tableData: [{ 
            name: 'A计划',
            code: 200333,
            retionRate: '30%',
            determineNatureRate: '50%',
            isEffect: 1,
            effectDate: '2018-05-02'
          }, {
            name: 'B计划',
            code: 200334,
            retionRate: '35%',
            determineNatureRate: '55%',
            isEffect: 1,
            effectDate: '2018-06-02'
          }],
          ruleForm: {
            nameLike: "",
            isEnable: ""
          },
          totalSize:0,
          currentPage: 1,
          isEffectStatus: {"1":"是","0":"否"},
        }
      },
      mounted() {
        this.init();
      },
      methods: {
        dateFormatter: function (row, column) {
            let datetime = row[column.property];
            if(datetime){
                datetime = new Date(datetime);
                let y = datetime.getFullYear() + '-';
                let mon = datetime.getMonth()+1 + '-';
                let d = datetime.getDate();
                return y + mon + d;
            }
            return ''
        },

        //查询
        submitForm() {
          this.init();
        },
        //重置
        resetForm() {
          this.ruleForm = {};
        },
        //评级设置
        levelSetting(index, row) {
        },
        //修改
        handleEdit(index, row) {
        },
        //浏览
        preview(index, row) {
        },
        //分配行业
        handleDistribution(index, row) {
        },
        handleSizeChange(val) {
        },
        handleCurrentChange(val) {
        },
        formatData(val){
         return this.isEffectStatus[val.isEffect] 
        },
        init(){
          let schemeSearchVO = this.ruleForm;
          this.$api.formPost(  "/api/biz/creditScheme/getCreditSchemeList",schemeSearchVO)
          .then(res => {
          console.log(res);
          if (res.retHead.code === "0000000") {
            console.log(res.retBody);
            this.tableData = res.retBody.list;
            this.totalSize = res.retBody.total;
          }
        });
        },
        addScheme(){
          this.$router.push({path:"/scheme/add"});
        }
    }
}
</script>